package com.kun.config.handler;

import com.kun.common.ResultDto;
import com.kun.common.exception.MyException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

//全局异常捕获
@RestControllerAdvice
public class MyExceptionHandler {

    /**
     * @param e 自定义异常
     * @return
     */
    @ExceptionHandler(MyException.class)
    @ResponseBody
    public Object returnMyCustomException(MyException e) {
        return ResultDto.fail(e.getCode(),e.getMessage());
    }

}
